//package com.zhouyu.exampleshiro.config;
//
//import com.zhouyu.exampleshiro.filter.AuthriFliter;
//import com.zhouyu.exampleshiro.filter.AuthtiFliter;
//import org.apache.shiro.authc.Authenticator;
//import org.apache.shiro.authc.pam.FirstSuccessfulStrategy;
//import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
//import org.apache.shiro.mgt.SecurityManager;
//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.context.annotation.Bean;
//
//import javax.servlet.Filter;
//import java.util.Arrays;
//import java.util.LinkedHashMap;
//import java.util.Map;
//
///**
// * shiro配置
// */
//public class ShiroConfiguration {
//    private static final Logger logger = LoggerFactory.getLogger(ShiroConfiguration.class);
//
//
//    /**
//     * 设置SecurityManager
//     *
//     * @return
//     */
//    @Bean
//    public SecurityManager securityManager() {
//        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
//        securityManager.setAuthenticator(authenticator());
//        return securityManager;
//    }
//
//    @Bean
//    public Authenticator authenticator() {
//        ModularRealmAuthenticator authenticator = new ModularRealmAuthenticator();
//        authenticator.setRealms(Arrays.asList(jwtAutiRealm(), myShiroRealm()));
//        authenticator.setAuthenticationStrategy(new FirstSuccessfulStrategy());
//        return authenticator;
//    }
//
//    /**
//     * 验证realm
//     *
//     * @return
//     */
//    @Bean
//    public JwtAutiRealm jwtAutiRealm() {
//        JwtAutiRealm jwtAutiRealm = new JwtAutiRealm();
//        return jwtAutiRealm;
//    }
//
//    /**
//     * 认证realm
//     *
//     * @return
//     */
//    @Bean
//    public JwtAuriRealm myShiroRealm() {
//        JwtAuriRealm myShiroRealm = new JwtAuriRealm();
//        return myShiroRealm;
//    }
//
//    @Bean
//    public AuthtiFliter authtiFliter() {
//        return new AuthtiFliter();
//    }
//
//    @Bean
//    public AuthriFliter authriFliter() {
//        return new AuthriFliter();
//    }
//
//
//    /**
//     * 拦截器
//     *
//     * @param securityManager
//     * @return
//     */
//
//    @Bean
//    public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
//        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
//        shiroFilterFactoryBean.setSecurityManager(securityManager);
////        //登录链接
////        shiroFilterFactoryBean.setLoginUrl("/login");
////        //登录成功后的链接
////        shiroFilterFactoryBean.setSuccessUrl("/index");
////        //错误页面，认证不通过跳转
////        shiroFilterFactoryBean.setUnauthorizedUrl("/error");
//        Map<String, Filter> filterMap = shiroFilterFactoryBean.getFilters();
//        filterMap.put("authti", authtiFliter());
//        filterMap.put("authri", authriFliter());
//        shiroFilterFactoryBean.setFilters(filterMap);
//
//        /*
//         * 链接拦截器:必须按照顺序来,这个是有序的，对所有用户认证的配置必须放在最后
//         * */
//        Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
//        //退出链接，已经自动实现
//        filterChainDefinitionMap.put("/logout", "logout");
//
//        // 配置不会被拦截的链接，一般是静态的资源文件
//        filterChainDefinitionMap.put("/static/**", "anon");
//
//        filterChainDefinitionMap.put("/user/sendMsg", "anon");
//        filterChainDefinitionMap.put("/user/login", "anon");
//        filterChainDefinitionMap.put("/home", "anon");
//        //对所有用户认证
//        filterChainDefinitionMap.put("/**", "authc");
//        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
//        return shiroFilterFactoryBean;
//    }
//
//}
